import { Component, OnInit } from '@angular/core';
import { MerchantapplyService } from '../../service/merchantapply.service';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
import { ComponentBasic } from '../../app.component';
@Component({
  selector: 'app-bandambassador',
  templateUrl: './merchantapply.component.html',
  styleUrls: ['./merchantapply.component.scss'],
  providers: [MerchantapplyService, CommonService]
})
export class MerchantapplyComponent extends ComponentBasic implements OnInit {
  loading = true;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  dataSet = [];
  isVisible = false;
  isinfoVisible = false;
  isOkLoading = false;
  roleItems: Array<any> = []
  doc: any = {};
  remarks: any;
  certificate: any;
  sdate: any;
  edate: any;
  iscontact: any;
  statuslist = [{ key: null, value: '全部' }, { key: '1', value: '已联系' }, { key: '0', value: '未联系' }];
  constructor(private merchantapplyservice: MerchantapplyService, private msg: NzMessageService, private commonservice: CommonService) {
    super();
    super.setLayout(true, true);
  }

  ngOnInit() {
    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.merchantapplyservice.query({
      offset: this.pageIndex,
      limit: this.pageSize,
      appbegintime: this.sdate,
      appendtime: this.edate,
      iscontact: this.iscontact
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
    });
  }
  //编辑备注
  Edit(id: any) {
    this.isinfoVisible = true;
    this.merchantapplyservice.querybyId({ _id: id }).then((res) => {
      this.doc = res;
    });
  }

  //标记联系
  EditConnect(id) {

    this.doc = this.merchantapplyservice.querybyId({ _id: id });
    let parm = {
      _id: id,
      remarks: this.doc.remarks
    }
    this.merchantapplyservice.updatestatus(parm).then((res) => {
      this.searchData();
    });
  }

  //确定修改
  handleOk(): void {
    this.isOkLoading = true;
    const parm = {
      _id: this.doc._id,
      remarks: this.doc.remarks
    }
    this.merchantapplyservice.updatestatus(parm).then((res) => {
      this.searchData();
      this.isinfoVisible = false;
      this.doc = {};
    });

  }

  handleCancel(): void {
    this.isinfoVisible = false;
    this.doc = {};
  }

  bhandleCancel(): void {
    this.isVisible = false;
  }

  bhandleOk(): void {
    this.isVisible = false;
  }

  BigPic(pic) {
    this.isVisible = true;
    this.certificate = pic;
  }
}
